<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Games:  Lights Out</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Andrew Gacek (andrew@dgi.net)">
<META NAME="section" CONTENT="Games">
<META NAME="description" CONTENT="Try to eliminate all the boxes to win.  When you check a box, all the squares around it (one above, one below, and one to each side) are unselected.  You can play in five different levels of difficulty.  Addictive!">

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Andrew Gacek (andrew@dgi.net) -->




<!-- Begin
function fillall() {
for (var i = 0; i < 24; i++) {
document.lightsform.elements[i].checked=1;
   }
}
function clearall() {
for (var i = 0; i < 24; i++) {
document.lightsform.elements[i].checked=0;
   }
}
function level1() {
clearall();
document.lightsform.elements[10].checked=1;
document.lightsform.elements[12].checked=1;
document.lightsform.elements[14].checked=1;
}
function level2() {
clearall();
document.lightsform.elements[12].checked=1;
document.lightsform.elements[16].checked=1;
document.lightsform.elements[17].checked=1;
document.lightsform.elements[18].checked=1;
document.lightsform.elements[20].checked=1;
document.lightsform.elements[21].checked=1;
document.lightsform.elements[22].checked=1;
document.lightsform.elements[23].checked=1;
document.lightsform.elements[24].checked=1;
}
function level3() {
fillall();
document.lightsform.elements[4].checked=0;
document.lightsform.elements[6].checked=0;
document.lightsform.elements[7].checked=0;
document.lightsform.elements[8].checked=0;
document.lightsform.elements[11].checked=0;
document.lightsform.elements[12].checked=0;
document.lightsform.elements[13].checked=0;
document.lightsform.elements[16].checked=0;
document.lightsform.elements[17].checked=0;
document.lightsform.elements[18].checked=0;
document.lightsform.elements[24].checked=0;
}
function level4() {
clearall();
document.lightsform.elements[2].checked=1;
document.lightsform.elements[6].checked=1;
document.lightsform.elements[8].checked=1;
document.lightsform.elements[10].checked=1;
document.lightsform.elements[12].checked=1;
document.lightsform.elements[14].checked=1;
document.lightsform.elements[16].checked=1;
document.lightsform.elements[18].checked=1;
document.lightsform.elements[22].checked=1;
 }
function level5() {
clearall();
document.lightsform.elements[11].checked=1;
document.lightsform.elements[16].checked=1;
document.lightsform.elements[21].checked=1;
}
function checkall() {
var win=1;
for (var i = 0; i < 24; i++) {
if (document.lightsform.elements[i].checked==1) {
win=0;
   }
}
if (win==1){
alert("\nYou Won!!\n")
   }
}
function check(v){
q=5;
w=1;
row=parseInt(v/q)+w;
if (isNaN(row)) {
row=1;
}
intv = parseInt(v);
a=eval(intv+q);
b=eval(intv-q);
c=eval(intv+w);
d=eval(intv-w);
if (a<0 || a>24){
a=25;
}
if (b<0 || b>24){
b=25;
}
if (c<0 || c>24){
c=25;
}
if (d<0 || d>24){
d=25;
}
kc = (parseInt(c/q)+w)
kd = (parseInt(d/q)+w)
kv = row;
if (kc != kv){
c=25;
}
if (kd != kv){
d=25;
}
if (v==5) d=25; // correction for strange bug
 
if (document.lightsform.elements[a].checked == 1) { 
document.lightsform.elements[a].checked=0;
} 
else {
document.lightsform.elements[a].checked=1;
}
if (document.lightsform.elements[b].checked == 1) { 
document.lightsform.elements[b].checked=0;
} 
else {
document.lightsform.elements[b].checked=1;
}
if (document.lightsform.elements[c].checked == 1) { 
document.lightsform.elements[c].checked=0;
} 
else {
document.lightsform.elements[c].checked=1;
}
if (document.lightsform.elements[d].checked == 1) { 
document.lightsform.elements[d].checked=0;
} 
else {
document.lightsform.elements[d].checked=1;
}
checkall();
}
//  End -->
</script>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width=600 cellpadding=0 cellspacing=10>
<tr>
<td width=468 align=center>

    
    
</td>
<td width=120 align=center>
    
</td>
</tr>
</table>
<BR>
<BR>
<basefont size=3>
<FONT SIZE="+2" FACE="Helvetica,Arial">
<A HREF="../index.htm" /" TARGET="_top"><FONT COLOR="#0000FF"><b>Home</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<A HREF="index.htm" /games/"><font color="#FF0000"><b>Games</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<FONT COLOR="#006666"><b>Lights Out</b></font></font>
<BR>
<BR>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->
Try to eliminate all the boxes to win.  When you check a box, all the squares around it (one above, one below, and one to each side) are unselected.  You can play in five different levels of difficulty.  Addictive!
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<center>
<form name=lightsform>
<table colspec="l20 l20 l20 l20 l20" border=7>
<tr>
<td><input type=checkbox value=0 onClick="check(value)"></td>
<td><input type=checkbox value=1 onClick="check(value)"></td>
<td><input type=checkbox value=2 onClick="check(value)"></td>
<td><input type=checkbox value=3 onClick="check(value)"></td>
<td><input type=checkbox value=4 onClick="check(value)"></td>
</tr>
<tr>
<td><input type=checkbox value=5 onClick="check(value)"></td>
<td><input type=checkbox value=6 onClick="check(value)"></td>
<td><input type=checkbox value=7 onClick="check(value)"></td>
<td><input type=checkbox value=8 onClick="check(value)"></td>
<td><input type=checkbox value=9 onClick="check(value)"></td>
</tr>
<tr>
<td><input type=checkbox value=10 onClick="check(value)"></td>
<td><input type=checkbox value=11 onClick="check(value)"></td>
<td><input type=checkbox value=12 onClick="check(value)"></td>
<td><input type=checkbox value=13 onClick="check(value)"></td>
<td><input type=checkbox value=14 onClick="check(value)"></td>
</tr>
<tr>
<td><input type=checkbox value=15 onClick="check(value)"></td>
<td><input type=checkbox value=16 onClick="check(value)"></td>
<td><input type=checkbox value=17 onClick="check(value)"></td>
<td><input type=checkbox value=18 onClick="check(value)"></td>
<td><input type=checkbox value=19 onClick="check(value)"></td>
</tr>
<tr>
<td><input type=checkbox value=20 onClick="check(value)"></td>
<td><input type=checkbox value=21 onClick="check(value)"></td>
<td><input type=checkbox value=22 onClick="check(value)"></td>
<td><input type=checkbox value=23 onClick="check(value)"></td>
<td><input type=checkbox value=24 onClick="check(value)"></td>
</tr>
</table>
<br>
<table border=1>
<tr>
<td><a href="javascript:level1()">level 1</a></td>
<td><a href="javascript:level2()">level 2</a></td>
</tr>
<tr>
<td><a href="javascript:level3()">level 3</a></td>
<td><a href="javascript:level4()">level 4</a></td>
</tr>
<tr>
<td><a href="javascript:level5()">level 5</a></td>
<td><input type="reset" value="clear"></td>
</tr>
</table>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Games:  Lights Out</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!
<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  5.86 KB" size=24>
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- TWO STEPS TO INSTALL LIGHTS OUT:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  --&gt;

&lt;!-- STEP ONE: Paste this code into the HEAD of your HTML document  --&gt;

&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- Original:  Andrew Gacek (andrew@dgi.net) --&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
function fillall() {
for (var i = 0; i &lt; 24; i++) {
document.lightsform.elements[i].checked=1;
   }
}
function clearall() {
for (var i = 0; i &lt; 24; i++) {
document.lightsform.elements[i].checked=0;
   }
}
function level1() {
clearall();
document.lightsform.elements[10].checked=1;
document.lightsform.elements[12].checked=1;
document.lightsform.elements[14].checked=1;
}
function level2() {
clearall();
document.lightsform.elements[12].checked=1;
document.lightsform.elements[16].checked=1;
document.lightsform.elements[17].checked=1;
document.lightsform.elements[18].checked=1;
document.lightsform.elements[20].checked=1;
document.lightsform.elements[21].checked=1;
document.lightsform.elements[22].checked=1;
document.lightsform.elements[23].checked=1;
document.lightsform.elements[24].checked=1;
}
function level3() {
fillall();
document.lightsform.elements[4].checked=0;
document.lightsform.elements[6].checked=0;
document.lightsform.elements[7].checked=0;
document.lightsform.elements[8].checked=0;
document.lightsform.elements[11].checked=0;
document.lightsform.elements[12].checked=0;
document.lightsform.elements[13].checked=0;
document.lightsform.elements[16].checked=0;
document.lightsform.elements[17].checked=0;
document.lightsform.elements[18].checked=0;
document.lightsform.elements[24].checked=0;
}
function level4() {
clearall();
document.lightsform.elements[2].checked=1;
document.lightsform.elements[6].checked=1;
document.lightsform.elements[8].checked=1;
document.lightsform.elements[10].checked=1;
document.lightsform.elements[12].checked=1;
document.lightsform.elements[14].checked=1;
document.lightsform.elements[16].checked=1;
document.lightsform.elements[18].checked=1;
document.lightsform.elements[22].checked=1;
 }
function level5() {
clearall();
document.lightsform.elements[11].checked=1;
document.lightsform.elements[16].checked=1;
document.lightsform.elements[21].checked=1;
}
function checkall() {
var win=1;
for (var i = 0; i &lt; 24; i++) {
if (document.lightsform.elements[i].checked==1) {
win=0;
   }
}
if (win==1){
alert("\nYou Won!!\n")
   }
}
function check(v){
q=5;
w=1;
row=parseInt(v/q)+w;
if (isNaN(row)) {
row=1;
}
intv = parseInt(v);
a=eval(intv+q);
b=eval(intv-q);
c=eval(intv+w);
d=eval(intv-w);
if (a&lt;0 || a&gt;24){
a=25;
}
if (b&lt;0 || b&gt;24){
b=25;
}
if (c&lt;0 || c&gt;24){
c=25;
}
if (d&lt;0 || d&gt;24){
d=25;
}
kc = (parseInt(c/q)+w)
kd = (parseInt(d/q)+w)
kv = row;
if (kc != kv){
c=25;
}
if (kd != kv){
d=25;
}
if (v==5) d=25; // correction for strange bug
 
if (document.lightsform.elements[a].checked == 1) { 
document.lightsform.elements[a].checked=0;
} 
else {
document.lightsform.elements[a].checked=1;
}
if (document.lightsform.elements[b].checked == 1) { 
document.lightsform.elements[b].checked=0;
} 
else {
document.lightsform.elements[b].checked=1;
}
if (document.lightsform.elements[c].checked == 1) { 
document.lightsform.elements[c].checked=0;
} 
else {
document.lightsform.elements[c].checked=1;
}
if (document.lightsform.elements[d].checked == 1) { 
document.lightsform.elements[d].checked=0;
} 
else {
document.lightsform.elements[d].checked=1;
}
checkall();
}
//  End --&gt;
&lt;/script&gt;
&lt;/HEAD&gt;

&lt;!-- STEP TWO: Copy this code into the BODY of your HTML document  --&gt;

&lt;BODY&gt;

&lt;center&gt;
&lt;form name=lightsform&gt;
&lt;table colspec="l20 l20 l20 l20 l20" border=7&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=checkbox value=0 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=1 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=2 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=3 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=4 onClick="check(value)"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=checkbox value=5 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=6 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=7 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=8 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=9 onClick="check(value)"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=checkbox value=10 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=11 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=12 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=13 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=14 onClick="check(value)"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=checkbox value=15 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=16 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=17 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=18 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=19 onClick="check(value)"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=checkbox value=20 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=21 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=22 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=23 onClick="check(value)"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=checkbox value=24 onClick="check(value)"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;table border=1&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="javascript:level1()"&gt;level 1&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="javascript:level2()"&gt;level 2&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="javascript:level3()"&gt;level 3&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="javascript:level4()"&gt;level 4&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="javascript:level5()"&gt;level 5&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type="reset" value="clear"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

 

&lt;!-- Script Size:  5.86 KB --&gt;</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>